package com.itheima.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.itheima.pojo.OrderSetting;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chencfgs
 * @date 2019-12-14 9:28
 */

public class OrderSettingListener extends AnalysisEventListener<OrderSetting> {

    private List<OrderSetting> orderSettings = new ArrayList<>();

    public List<OrderSetting> getOrderSetting() {
        return orderSettings;
    }


    @Override
    public void invoke(OrderSetting orderSetting, AnalysisContext analysisContext) {
        Integer currentRowNum = analysisContext.getCurrentRowNum();
        currentRowNum += 1;
        if (orderSetting.getOrderDate() == null) {
            throw new RuntimeException("第" + currentRowNum + "行日期有误,请检查后再上传");
        }
        if (orderSetting.getNumber() < 0) {
            throw new RuntimeException("第" + currentRowNum + "行可预约数量有误,请检查后再上传");
        }
        orderSettings.add(orderSetting);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
